<?php
/* [$WindsForce] (C)Hunzhiwange.COM Since 2014.07.28.
   家居商家家装套餐控制器($$)*/

!defined('Q_PATH') && exit;

class JiajupackageController extends AController{

	public function filter_(&$arrMap){
		$arrMap['A.jiajupackage_title']=array('like',"%".Q::G('jiajupackage_title')."%");
		$arrMap['A.jiajupackage_viewnum']=array('egt',intval(Q::G('jiajupackage_viewnum')));
		if(Q::G('jiajupackage_price')){
			$arrMap['A.jiajupackage_price']=array('egt',Q::G('jiajupackage_price'));
		}
		
		// 添加时间
		$this->getTime_('A.create_dateline',$arrMap);

		// 待审
		$this->getAudit_('A.jiajupackage_status',$arrMap);
	}

	public function index($sModel=null,$bDisplay=true){
		parent::index('jiajupackage',false);
		$this->display(Admin_Extend::template('jiaju','jiajupackage/index'));
	}

	protected function sqljoin_(){
		return "->join('".Q::C('DB_PREFIX')."jiajucompany AS C','C.jiajucompany_id,C.jiajucompany_fullname,C.jiajucompany_isfvip,C.jiajucompany_domain','A.jiajucompany_id=C.jiajucompany_id')";
	}

	public function bEdit_(){
		$nId=intval(Q::G('value','G'));
		// 套餐内容
		$sContent=JiajupackagecontentModel::F('jiajupackage_id=?',$nId)->getColumn('jiajupackage_content');
		$this->assign('arrConfigData',json_decode($sContent,true));
		$this->assign('arrConfigTitle',json_decode($GLOBALS['_cache_']['jiaju_option']['package_config'],true));
	}

	public function edit($sMode=null,$nId=null,$bDidplay=true){
		$nId=intval(Q::G('value','G'));
		$this->bEdit_();
		parent::edit('jiajupackage',$nId,false);
		$this->display(Admin_Extend::template('jiaju','jiajupackage/add'));
	}

	public function add(){
		$this->bAdd_();
		$this->display(Admin_Extend::template('jiaju','jiajupackage/add'));
	}
	
	public function bAdd_(){
		$this->assign('arrConfigTitle',json_decode($GLOBALS['_cache_']['jiaju_option']['package_config'],true));
	}

	public function insert($sModel=null,$nId=null){
		$oJiajupackage=new JiajupackageModel();
		$oJiajupackage->saveData(intval(Q::G('jiajucompany_id')));
		if($oJiajupackage->isError()){
			$this->E($oJiajupackage->getErrorMessage());
		}

		$this->A($oJiajupackage->toArray(),'套餐添加成功',1);
	}

	public function update($sModel=null,$nId=null){
		$nId=intval(Q::G('value'));
		
		$oJiajupackage=JiajupackageModel::F('jiajupackage_id=?',$nId)->getOne();
		$oJiajupackage->updateData(intval(Q::G('jiajucompany_id')));
		if($oJiajupackage->isError()){
			$this->E($oJiajupackage->getErrorMessage());
		}

		$this->S('套餐更新成功');
	}

	public function forbid($sModel=null,$sId=null,$bApp=false){
		$nId=intval(Q::G('value','G'));
		parent::forbid('jiajupackage',$nId,true);
	}

	public function resume($sModel=null,$sId=null,$bApp=false){
		$nId=intval(Q::G('value','G'));
		parent::resume('jiajupackage',$nId,true);
	}

	public function clear_recycle($sModel=null,$sField='status'){
		parent::clear_recycle('jiajupackage',$sField);
	}

	public function foreverdelete_deep($sModel=null,$sId=null){
		$sId=Q::G('value');
		parent::foreverdelete_deep('jiajupackage',$sId);
	}

	public function foreverdelete($sModel=null,$sId=null,$bApp=false){
		$sId=Q::G('value');
		parent::foreverdelete('jiajupackage',$sId,true);
	}

	public function view_preview($sMode=null,$nId=null,$bDidplay=true){
		$nId=intval(Q::G('value','G'));
		$this->bEdit_();
		parent::view_preview('jiajupackage',$nId,false);
		$this->display(Admin_Extend::template('jiaju','jiajupackage/viewpreview'));
	}

	public function save_preview($sMode=null,$nId=null){
		$nId=intval(Q::G('value','G'));
		parent::save_preview('jiajupackage',$nId);
	}

	public function save_previewstatus($sMode=null,$nId=null){
		$nId=intval(Q::G('value','G'));
		parent::save_previewstatus('jiajupackage',$nId);
	}

}
